<template>
	<view>
		<!-- 搜索历史 -->
		<template v-if="searchList.length===0">
			<view class=" my-2 font-md px-1">
				搜索历史
			</view>
			<!-- 历史标签 -->
			<view class="flex flex-wrap">
				<view class="border rounded mx-1 my-1 py px-2" v-for="(item ,index) in list" :key="index" @click="clickSearchHistory(item)">
					{{item}}
				</view>
			</view>
		</template>
		<template v-eles>
			<!-- 数据列表组件 -->
			<block v-for="(item,index) in searchList">
				<common-list :item="item" :index="index"></common-list>
			</block>
		</template>
	</view>
</template>

<script>
	var demoData = [{
			"username": "昵称",
			"userpic": "/static/default.jpg",
			"isFollow": true,
			"newstime": "2019-11-11 下午 4:30",
			"title": "我是标题",
			"titlepic": "/static/demo/datapic/1.jpg",
			"support": {
				"type": "",
				"support_count": 0,
				"unsupport_count": 0,
			},
			"comment_count": 0,
			"share_num": 0
		}, {
			"username": "昵称",
			"userpic": "/static/default.jpg",
			"isFollow": true,
			"newstime": "2019-11-11 下午 4:30",
			"title": "我是标题",
			"titlepic": "/static/demo/datapic/1.jpg",
			"support": {
				"type": "",
				"support_count": 0,
				"unsupport_count": 0,
			},
			"comment_count": 0,
			"share_num": 0
		},
		{
			"username": "昵称",
			"userpic": "/static/default.jpg",
			"isFollow": true,
			"newstime": "2019-11-11 下午 4:30",
			"title": "我是标题",
			"titlepic": "/static/demo/datapic/1.jpg",
			"support": {
				"type": "",
				"support_count": 0,
				"unsupport_count": 0,
			},
			"comment_count": 0,
			"share_num": 0
		}
	]
	import commonList from "@/components/common/common-list.vue"
	export default {

		components: {
			commonList
		},
		data() {
			return {
				searchList: [],
				searchVal: "",
				list: ["小米手机10", "红米手机", "无线快冲", "宇通客车"]
			}
		},
		methods: {

			//点击搜索标签
			clickSearchHistory(item) {
				this.searchVal = item;
				this.searchEvent();
			},
			//搜索事件
			onNavigationBarSearchInputChanged(e) {
				this.searchVal = e.text;
			},
			//点击搜索结果
			onNavigationBarButtonTap(e) {
				if (e.index === 0) {
					this.searchEvent()
				}

			},
			// 搜索事件
			searchEvent() {
				//先收起键盘
				uni.hideKeyboard()
				//显示loadding
				uni.showLoading({
					title: "加载中……",
					mask: false,
				})
				//发送请求
				setTimeout(() => {
					//隐藏lodding……
					uni.hideLoading()
					this.searchList = demoData;

				}, 5000)


			}



		}
	}
</script>

<style>

</style>
